Skip to content

Decouple AgentServer responses from generated model internals#47995

Open
Shivakishore14 wants to merge 13 commits into
mainfrom
sshiva/agentserver-typeddict-local
Open

Decouple AgentServer responses from generated model internals#47995
Shivakishore14 wants to merge 13 commits into
mainfrom
sshiva/agentserver-typeddict-local

Conversation

@Shivakishore14

@Shivakishore14 Shivakishore14 commented Jul 10, 2026

Copy link
Copy Markdown
Member

Summary

  • Regenerate AgentServer response contracts as local TypedDict/dict-native models from the current sdk-service-agents-contracts TypeSpec path.
  • Point tsp-location.yaml at the dependent spec PR commit 7691586c2d80a49c4b11afefb171b3d8a9e7bc1b from Fix AgentServer response model contracts azure-rest-api-specs#44689.
  • Keep runtime code decoupled from generated model internals while preserving generated validators and API docs.
  • Merged latest main and aligned the generated _enums shim/import shape with the current AgentServer changes on main.

Depends on

Validation

  • make generate-models using pinned published emitters from latest eng/emitter-package.json (@azure-tools/typespec-python 0.63.3 / @typespec/http-client-python 0.34.2)
  • make generate-openapi
  • make generate-validators
  • .venv/bin/azpysdk apistub .
  • PYTHONPATH=. .venv/bin/python -m pytest tests/unit tests/contract tests/interop -q957 passed, 1 warning

Move response contracts to local TypedDict wire payloads and remove runtime reliance on generated model constructors, serialization helpers, and nested generated SDK model paths.

Keep validation behind a stable local wrapper and update tests to exercise dict-native payloads instead of generated model runtime callability.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Hosted Agents sdk/agentserver/* label Jul 10, 2026
Shivakishore14 and others added 4 commits July 10, 2026 12:44
Use the source-built TypeSpec Python emitter TypedDict output as the model source instead of the localized bridge artifact.

Normalize the emitted package into the local AgentServer generated boundary and remove fake model_base/_models compatibility shims.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pin AgentServer TypeSpec generation to the source PR that removes stale OpenAI usage decorators and enables Python TypeDict generation.

Replace the old finalization script with a minimal contract extractor, regenerate API docs and model contracts, and remove unused _types.py output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 4ead3de5-a3b3-4d3a-bf93-a4ee397d7498
Regenerate AgentServer response TypedDict contracts, validators, and API docs from the current AgentServer service contract path. Point tsp-location.yaml at the fresh spec PR commit and compile from the clean synced Foundry/src root.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4ead3de5-a3b3-4d3a-bf93-a4ee397d7498
Shivakishore14 and others added 7 commits July 16, 2026 06:54
Inline the single-use wire field mutation helper and remove a thin Foundry serializer wrapper that only delegated to to_wire_dict.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4ead3de5-a3b3-4d3a-bf93-a4ee397d7498
Generate the TypedDict enum fallback at the root _generated package so validators use the same _enums import shape as latest main.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4ead3de5-a3b3-4d3a-bf93-a4ee397d7498
Point AgentServer Responses generation metadata at the latest spec PR commit after CI-only validation fixes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 4ead3de5-a3b3-4d3a-bf93-a4ee397d7498
Address runtime dict-native response compatibility, static analysis, spelling, and Sphinx documentation failures for the AgentServer Responses package.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 4ead3de5-a3b3-4d3a-bf93-a4ee397d7498
Update samples to use TypedDict-safe access and required discriminator fields so package Pyright validation passes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 4ead3de5-a3b3-4d3a-bf93-a4ee397d7498
@Shivakishore14
Shivakishore14 marked this pull request as ready for review July 17, 2026 08:09
Copilot AI review requested due to automatic review settings July 17, 2026 08:09
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates AgentServer response contracts from generated runtime model classes to local TypedDict-backed wire dictionaries.

Changes:

  • Regenerates contracts and validators from the dependent TypeSpec specification.
  • Updates runtime, storage, streaming, samples, and tests for dictionary-native payloads.
  • Adds extraction tooling and removes obsolete generated-model shims.

Reviewed changes

Copilot reviewed 95 out of 101 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
type_spec/tsp-location.yaml Updates TypeSpec source and commit.
tests/unit/test_validation.py Tests dictionary-native validation errors.
tests/unit/test_string_content_expansion.py Updates content expansion tests.
tests/unit/test_sse_writer.py Uses dictionary SSE events.
tests/unit/test_session_and_response_id_resolution.py Simplifies parsed request fixture.
tests/unit/test_runtime_state.py Uses TypedDict response snapshots.
tests/unit/test_response_execution.py Updates response execution fixture.
tests/unit/test_response_event_stream_builder.py Tests dictionary event streams.
tests/unit/test_resolve_input_items_for_persistence.py Updates persistence fixtures.
tests/unit/test_input_items_provider_behavior.py Uses TypedDict responses.
tests/unit/test_in_memory_provider_crud.py Tests dictionary storage behavior.
tests/unit/test_id_generator.py Tests discriminator-based ID dispatch.
tests/unit/test_generated_payload_validation.py Uses validator wrapper.
tests/unit/test_foundry_storage_provider.py Updates storage payload fixtures.
tests/unit/test_event_stream_generators.py Verifies dictionary events.
tests/unit/test_emit_return_types.py Checks event wire discriminators.
tests/unit/test_builders.py Updates builder assertions.
tests/interop/test_sdk_round_trip.py Uses mapping-style requests.
tests/interop/test_openai_wire_compliance.py Updates wire-contract assertions.
tests/e2e/test_proxy_e2e.py Uses dictionary requests upstream.
tests/contract/test_stream_provider_fallback.py Uses public model exports.
tests/contract/test_stream_event_lifecycle.py Uses public model exports.
tests/contract/test_response_invariants.py Reads dictionary agent references.
tests/contract/test_bg_isolation_propagation.py Uses public model exports.
samples/sample_16_structured_outputs.py Builds structured-output dictionaries.
samples/sample_15_annotations.py Builds annotation dictionaries.
samples/sample_14_file_inputs.py Reads file input mappings.
samples/sample_13_image_input.py Reads image input mappings.
samples/sample_11_non_streaming_upstream.py Forwards dictionary inputs.
samples/sample_10_streaming_upstream.py Builds dictionary snapshots.
samples/sample_07_customization.py Demonstrates mapping access.
samples/sample_05_conversation_history.py Reads dictionary history.
samples/sample_04_function_calling.py Detects calls by discriminator.
samples/sample_03_full_control.py Mutates response mappings.
pyproject.toml Packages generated typing marker.
Makefile Generates and extracts TypedDict contracts.
cspell.json Adds generated terminology.
streaming/_text_response.py Uses public wire types.
streaming/_state_machine.py Uses public enums and mappings.
streaming/_sse.py Encodes mapping-only events.
streaming/_builders/_reasoning.py Returns TypedDict events.
streaming/_builders/_function.py Uses public wire contracts.
streaming/_builders/_base.py Validates dictionary item payloads.
store/_memory.py Persists dictionary snapshots.
store/_foundry_serializer.py Serializes wire dictionaries.
store/_foundry_provider.py Uses public model aliases.
store/_base.py Updates provider protocol types.
models/runtime.py Stores dictionary execution state.
models/errors.py Builds dictionary error envelopes.
models/_wire.py Adds wire normalization helpers.
models/_validators.py Wraps generated validation.
models/_generated/sdk/models/models/_patch.py Removes legacy customizations.
models/_generated/sdk/models/_types.py Removes legacy unions.
models/_generated/sdk/models/__init__.py Removes legacy package surface.
models/_generated/py.typed Marks generated contracts typed.
models/_generated/models/_patch.py Adds generated patch scaffold.
models/_generated/models/__init__.py Initializes patch surface.
models/_generated/_unions.py Adds generated unions.
models/_generated/_patch.py Removes compatibility shim.
models/_generated/_models.py Removes compatibility shim.
models/_generated/__init__.py Exports TypedDicts and enum shims.
models/__init__.py Builds the public model surface.
hosting/_validation.py Validates and returns wire dictionaries.
hosting/_runtime_state.py Copies dictionary snapshots.
hosting/_routing.py Updates handler contract types.
hosting/_request_parsing.py Resolves identity from mappings.
hosting/_observability.py Copies mapping-based tags.
hosting/_execution_context.py Uses public model types.
hosting/_event_subject.py Publishes dictionary events.
hosting/_endpoint_handler.py Normalizes dictionary HTTP payloads.
_response_context.py Resolves dictionary input items.
_id_generator.py Dispatches IDs by wire discriminator.
api.metadata.yml Updates API snapshot metadata.
_scripts/validator_emitter.py Resolves Literal enum values.
_scripts/validation-overlay.yaml Makes function-call IDs optional.
_scripts/generated_shims/sdk_models__init__.py Removes obsolete shim.
_scripts/generated_shims/models_patch.py Removes obsolete customization.
_scripts/generated_shims/_patch.py Removes obsolete patch shim.
_scripts/generated_shims/_models.py Removes obsolete model shim.
_scripts/generated_shims/_enums.py Removes obsolete enum shim.
_scripts/generated_shims/__init__.py Removes obsolete package shim.
_scripts/extract_model_contracts.py Extracts generated TypedDict contracts.
Comments suppressed due to low confidence (1)

sdk/agentserver/azure-ai-agentserver-responses/azure/ai/agentserver/responses/models/init.py:44

  • The new export construction drops the previously public ResponseIncompleteReason enum, while ResponseEventStream.emit_incomplete() still documents azure.ai.agentserver.responses.models.ResponseIncompleteReason. Either restore this hand-written enum in the public model surface or remove/update the stale reference and explicitly account for the breaking API change.
__all__ = [
    "ResponseStatus",
    "TerminalResponseStatus",
    "get_content_expanded",
    "get_conversation_expanded",
    "get_conversation_id",
    "get_input_expanded",
    "get_tool_choice_expanded",
    *_generated_all,

"type": error_type,
}
if debug_info is not None:
error["debug_info"] = debug_info
assert completed["response"]["status"] == "completed"
assert completed["response"]["usage"]["total_tokens"] == 3
assert isinstance(completed["response"]["completed_at"], int)
assert completed["response"]["completed_at"] is not None
directory: specification/ai-foundry/data-plane/Foundry/src/sdk-service-agentserver-contracts
commit: d5cf570f983359ce3045f08715ae862455e1d501
directory: specification/ai-foundry/data-plane/Foundry/src
commit: bac84364671d807a15c8ffec4f8db3ece8c53742
Regenerate AgentServer response contracts from the rapida/add-agentserver-view spec branch and restore the SDK TypeSpec pointer layout to the main SDK shape with only the commit updated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 4ead3de5-a3b3-4d3a-bf93-a4ee397d7498
Copilot AI review requested due to automatic review settings July 17, 2026 12:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 96 out of 101 changed files in this pull request and generated 6 comments.

@@ -1,5 +1,5 @@
directory: specification/ai-foundry/data-plane/Foundry/src/sdk-service-agentserver-contracts
commit: d5cf570f983359ce3045f08715ae862455e1d501
commit: 8bfd173c3afb9c85495293bffc04f6dcd4295548
Comment on lines +389 to +393
"reasoning": IdGenerator.new_reasoning_item_id,
"compaction": IdGenerator.new_compaction_item_id,
"compaction_summary": IdGenerator.new_compaction_item_id,
"structured_outputs": IdGenerator.new_structured_output_item_id,
}
"type": error_type,
}
if debug_info is not None:
error["debug_info"] = debug_info
Comment on lines +20 to +28
_TYPE_EXPORT_EXCLUDES = {
"Any",
"Literal",
"Optional",
"Required",
"TYPE_CHECKING",
"TypedDict",
"Union",
}
Comment on lines +81 to +82
payload = event.copy() if isinstance(event, dict) else dict(event.items())
event_type = payload.get("type")
Comment on lines +29 to +33
_generated_all = [
name
for module in (_generated_types, _generated_unions)
for name in dir(module)
if not name.startswith("_") and name not in _TYPE_EXPORT_EXCLUDES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants